package it.inefficienza.test.spring.service;

import it.inefficienza.test.spring.model.Contact;
import it.inefficienza.test.spring.persistence.ContactMapper;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class ContactService {

	@Autowired
	private ContactMapper contactMapper;

	@Transactional
	public void addContact(Contact contact) {
		//		contactDAOImpl.addContact(contact);
		contactMapper.create(contact);
	}

	@Transactional
	public List<Contact> listContact() {

		// return null; //contactDAOImpl.listContact();
		return contactMapper.list();

		/*
		List<Contact> contacts = new ArrayList<Contact>();
		Contact c1 = new Contact();
		c1.setId(1L);
		c1.setFirstname("Pino");
		c1.setLastname("Panino");
		contacts.add(c1);

		Contact c2 = new Contact();
		c2.setId(1L);
		c2.setFirstname("Gino");
		c2.setLastname("Gelato");
		contacts.add(c2);



		return contacts;
		*/

	}

	@Transactional
	public void removeContact(Long id) {
		//    	contactDAOImpl.removeContact(id);
		contactMapper.delete(id);
	}

	@Transactional
	public Contact getContact(Long contactId) {
		return contactMapper.read(contactId);
	}

	@Transactional
	public void updateContact(Contact contact) {
		contactMapper.update(contact);
	}


}